﻿Imports Cls_Common
Imports VSModel
Imports System.Data
Partial Class FrontEnd_Control_Store_Home
    Inherits System.Web.UI.UserControl
    Public strSalonURL As String = ""
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If Not IsPostBack Then
            Dim script As ScriptManager = ScriptManager.GetCurrent(Me.Page)
            If Not script Is Nothing AndAlso script.IsInAsyncPostBack Then
                ScriptManager.RegisterStartupScript(Me.Page, Me.Page.GetType, "abc", "ajaxJquery()", True)
            Else
                Me.Page.ClientScript.RegisterStartupScript(Me.Page.GetType(), "abc", String.Concat("Sys.Application.add_load(function(){", "ajaxJquery()", "});"), True)
            End If
            If Not Page.RouteData.Values("Id") Is Nothing Then
                BindBasicInfo(Page.RouteData.Values("Id"))
            End If
        End If
    End Sub
    Protected Sub BindBasicInfo(ByVal _id As Integer)
        Using _data As New VSEntities
            Dim p = (From q In _data.Stores Where q.StoreId = _id Select q).FirstOrDefault
            If Not p Is Nothing Then
                hplTitle.Text = p.Title
                Page.Title = p.Title
                Page.MetaDescription = p.Description

                ltrDiaChi.Text = p.DiaChi
                ltrDescription.Text = p.Description

                ltrDienThoai.Text = p.Phone
                ltrABN.Text = p.ContactUs
                ltrEmail.Text = p.Email
                ltrURL.Text = p.URLWEB
                'If Not p.PhoneOther Is Nothing Then
                '    ltrDienThoai.Text = p.Phone & " - " & p.PhoneOther
                'End If
                hidStoreId.Value = p.UserId
                strSalonURL = p.QueryString & "-" & p.StoreId.ToString & "/"

                Dim k = (From q In _data.StoreImages Where q.StoreId = p.StoreId Select q).Take(9).ToList
                If k.Count > 0 Then
                    rptBigBanner.DataSource = k
                    rptBigBanner.DataBind()

                    With rptImageThumb
                        .DataSource = k
                        .DataBind()
                    End With

                End If
            End If
        End Using
    End Sub
    Protected Sub rptBigBanner_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptBigBanner.ItemDataBound
        Dim row As StoreImage = e.Item.DataItem
        Dim HighslideImage1 As Encosia.HighslideImage = e.Item.FindControl("HighslideImage1")
        HighslideImage1.ImageUrl = CookedImageURL("420-300", row.ImageURL)
        HighslideImage1.FullImageURL = CookedImageURL("800-600", row.ImageURL)
        If e.Item.ItemIndex = 0 Then
            HighslideImage1.Attributes.Add("style", "display:inline")
        Else
            HighslideImage1.Attributes.Add("style", "display:none")
        End If

    End Sub
    Protected Sub rptImageThumb_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.RepeaterItemEventArgs) Handles rptImageThumb.ItemDataBound
        Dim row As StoreImage = e.Item.DataItem
        Dim imgThumb As Image = e.Item.FindControl("imgThumb")
        imgThumb.ImageUrl = CookedImageURL("90-60", row.ImageURL)
    End Sub
End Class
